package com.yj.map;

import java.util.*;

/**
 * 遍历map的4种方式
 */
public class MapDemo{


    public static void main(String[] args) {

        Map<String,String> map = new HashMap<>();
        map.put("name", "join");
        map.put("age", "18");
        map.put("address", "shenzhen");


        //region for循环遍历map
        for (Map.Entry<String, String> entry : map.entrySet()) {
            System.out.println(entry.getKey());
            System.out.println(entry.getValue());
        }
        //endregion

        //region map.keySet
        Set<String> strings = map.keySet();
        for (String string : strings) {
            System.out.println(string);
        }
        //endregion

        Collection<String> values = map.values();
        for (String value : values) {
            System.out.println(value);
        }
        System.out.println("=====");
        Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()){
            Map.Entry<String, String> next = iterator.next();
            System.out.println(next.getKey());
            System.out.println(next.getValue());
        }


    }

}
